load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_benchmark", "mongo_cc_binary", "mongo_cc_library", "mongo_cc_unit_test", "windows_rc")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

idl_generator(
    name = "analyze_shard_key_documents_gen",
    src = "analyze_shard_key_documents.idl",
    deps = [
        ":analyze_shard_key_common_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/pipeline:legacy_runtime_constants_gen",
    ],
)

idl_generator(
    name = "analyze_shard_key_common_gen",
    src = "analyze_shard_key_common.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "router_transactions_stats_gen",
    src = "router_transactions_stats.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "balancer_feature_flag_gen",
    src = "balancer_feature_flag.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "balancer_configuration_gen",
    src = "balancer_configuration.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

mongo_cc_library(
    name = "sharding_helpers",
    srcs = [
        "shard_targeting_helpers.cpp",
    ],
    no_undefined_ref_DO_NOT_USE = False,
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:common",
        "//src/mongo/db/query/collation:collator_interface",
    ],
)

mongo_cc_library(
    name = "sharding_router_api",
    srcs = [
        "multi_statement_transaction_requests_sender.cpp",
        "router_transactions_metrics.cpp",
        "session_catalog_router.cpp",
        "transaction_router.cpp",
        "transaction_router_resource_yielder.cpp",
        ":router_transactions_stats_gen",
        "//src/mongo/db/global_catalog/ddl:cluster_ddl.cpp",
        "//src/mongo/db/router_role:cluster_commands_helpers.cpp",
        "//src/mongo/db/router_role:collection_routing_info_targeter.cpp",
        "//src/mongo/db/router_role:collection_uuid_mismatch.cpp",
        "//src/mongo/db/router_role:router_role.cpp",
        "//src/mongo/db/router_role:routing_context.cpp",
        "//src/mongo/db/topology/cluster_parameters:set_cluster_server_parameter_router_impl.cpp",
        "//src/mongo/s/query:shard_key_pattern_query_util.cpp",
    ],
    deps = [
        ":async_requests_sender",
        ":grid",
        ":query_analysis_sampler",
        ":sharding_helpers",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:mongohasher",
        "//src/mongo/db:shared_request_handling",
        "//src/mongo/db/commands:txn_cmd_request",
        "//src/mongo/db/pipeline/process_interface:mongo_process_interface",
        "//src/mongo/db/query:query_planner",
        "//src/mongo/db/query/query_settings:query_settings_service_dependencies",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db/repl:read_concern_args",
        "//src/mongo/db/session:logical_session_id_helpers",
        "//src/mongo/db/session:session_catalog",
        "//src/mongo/db/session:sessions_collection",
        "//src/mongo/db/shard_role:resource_yielders",
        "//src/mongo/db/shard_role/lock_manager",
        "//src/mongo/db/shard_role/shard_catalog:collection_uuid_mismatch_info",
        "//src/mongo/db/stats:transaction_stats",
        "//src/mongo/db/timeseries:timeseries_metadata",
        "//src/mongo/rpc:command_status",
        "//src/mongo/util/concurrency:spin_lock",
    ],
)

mongo_cc_library(
    name = "async_requests_sender",
    srcs = [
        "async_requests_sender.cpp",
    ],
    deps = [
        ":grid",
        "//src/mongo/db/query:command_request_response",
        "//src/mongo/db/sharding_environment:mongos_server_parameters",
        "//src/mongo/executor:scoped_task_executor",
        "//src/mongo/executor:task_executor_interface",
        "//src/mongo/s/client:shard_interface",
        "//src/mongo/s/client:sharding_client",
    ],
)

mongo_cc_library(
    name = "query_analysis_sampler",
    srcs = [
        "query_analysis_client.cpp",
        "query_analysis_sampler.cpp",
        "query_analysis_sampler_util.cpp",
        "query_analysis_server_status.cpp",
    ],
    deps = [
        ":analyze_shard_key_common",
        ":grid",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db/shard_role/lock_manager",
    ],
)

idl_generator(
    name = "sharding_task_executor_pool_gen",
    src = "sharding_task_executor_pool.idl",
)

# This library contains sharding functionality used by both mongod and mongos
mongo_cc_library(
    name = "grid",
    srcs = [
        "balancer_configuration.cpp",
        "//src/mongo/db/global_catalog/ddl:shard_util.cpp",
        "//src/mongo/db/router_role/routing_cache:catalog_cache.cpp",
        "//src/mongo/db/router_role/routing_cache:catalog_cache_loader.cpp",
        "//src/mongo/db/router_role/routing_cache:config_server_catalog_cache_loader_impl.cpp",
        "//src/mongo/db/router_role/routing_cache:routing_information_cache.cpp",
        "//src/mongo/db/sharding_environment:cluster_identity_loader.cpp",
        "//src/mongo/db/sharding_environment:grid.cpp",
        "//src/mongo/db/sharding_environment:router_uptime_reporter.cpp",
        "//src/mongo/db/sharding_environment/client:config_shard_wrapper.cpp",
        "//src/mongo/db/sharding_environment/client:shard_factory.cpp",
        "//src/mongo/db/topology:shard_registry.cpp",
    ],
    deps = [
        ":common_s",
        "//src/mongo/client:clientdriver_network",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db:server_base",
        "//src/mongo/db/exec:scoped_timer",
        "//src/mongo/db/repl:replica_set_messages",
        "//src/mongo/db/shard_role/lock_manager",
        "//src/mongo/db/topology/vector_clock:logical_time_metadata_hook",
        "//src/mongo/db/update:update_common",
        "//src/mongo/executor:task_executor_pool",
        "//src/mongo/s/client:shard_interface",
        "//src/mongo/s/query/exec:cluster_cursor_manager",
        "//src/mongo/util:caching",
        "//src/mongo/util/concurrency:spin_lock",
        "//src/mongo/util/concurrency:thread_pool",
    ],
)

idl_generator(
    name = "analyze_shard_key_server_parameters_gen",
    src = "analyze_shard_key_server_parameters.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

mongo_cc_library(
    name = "load_balancer_support",
    srcs = [
        "load_balancer_support.cpp",
    ],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/repl/hello:hello_command",
        "//src/mongo/db/sharding_environment:mongos_server_parameters",
    ],
)

mongo_cc_library(
    name = "analyze_shard_key_common",
    srcs = [
        "analyze_shard_key_common.cpp",
        "analyze_shard_key_role.cpp",
        "query_analysis_sample_tracker.cpp",
        ":analyze_shard_key_common_gen",
        ":analyze_shard_key_documents_gen",
        ":analyze_shard_key_server_parameters_gen",
    ],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db/pipeline:runtime_constants_idl",
        "//src/mongo/db/repl:read_concern_args",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/repl:repl_settings",
    ],
)

idl_generator(
    name = "analyze_shard_key_cmd_gen",
    src = "analyze_shard_key_cmd.idl",
    deps = [
        ":analyze_shard_key_common_gen",
        "//src/mongo/client:read_preference_setting_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:keypattern_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "configure_query_analyzer_cmd_gen",
    src = "configure_query_analyzer_cmd.idl",
    deps = [
        ":analyze_shard_key_common_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "refresh_query_analyzer_configuration_cmd_gen",
    src = "refresh_query_analyzer_configuration_cmd.idl",
    deps = [
        ":analyze_shard_key_common_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

mongo_cc_library(
    name = "add_shard_idl",
    srcs = ["//src/mongo/db/topology:add_shard_gen"],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db/global_catalog:type_shard_identity_idl",
    ],
)

mongo_cc_library(
    name = "common_s",
    srcs = [
        "analyze_shard_key_cmd_gen",
        "cluster_umc_error_with_write_concern_error_info.cpp",
        "configure_query_analyzer_cmd_gen",
        "refresh_query_analyzer_configuration_cmd_gen",
        "transaction_participant_failed_unyield_exception.cpp",
        "would_change_owning_shard_exception.cpp",
        ":balancer_configuration_gen",
        ":balancer_feature_flag_gen",
        "//src/mongo/db/global_catalog:chunk.cpp",
        "//src/mongo/db/global_catalog:chunk_manager.cpp",
        "//src/mongo/db/global_catalog:shard_key_pattern.cpp",
        "//src/mongo/db/global_catalog:type_changelog.cpp",
        "//src/mongo/db/global_catalog:type_chunk.cpp",
        "//src/mongo/db/global_catalog:type_chunk_base_gen",
        "//src/mongo/db/global_catalog:type_chunk_range.cpp",
        "//src/mongo/db/global_catalog:type_chunk_range_base_gen",
        "//src/mongo/db/global_catalog:type_collection.cpp",
        "//src/mongo/db/global_catalog:type_collection_common_types_gen",
        "//src/mongo/db/global_catalog:type_collection_gen",
        "//src/mongo/db/global_catalog:type_config_version_gen",
        "//src/mongo/db/global_catalog:type_database_gen",
        "//src/mongo/db/global_catalog:type_mongos.cpp",
        "//src/mongo/db/global_catalog:type_namespace_placement_gen",
        "//src/mongo/db/global_catalog:type_remove_shard_event_gen",
        "//src/mongo/db/global_catalog:type_shard.cpp",
        "//src/mongo/db/global_catalog:type_tags.cpp",
        "//src/mongo/db/global_catalog/ddl:add_shard_to_zone_gen",
        "//src/mongo/db/global_catalog/ddl:cannot_implicitly_create_collection_info.cpp",
        "//src/mongo/db/global_catalog/ddl:drop_collection_if_uuid_not_matching_gen",
        "//src/mongo/db/global_catalog/ddl:ensure_chunk_version_is_greater_than_gen",
        "//src/mongo/db/global_catalog/ddl:merge_chunk_request_gen",
        "//src/mongo/db/global_catalog/ddl:migration_blocking_operation_gen",
        "//src/mongo/db/global_catalog/ddl:move_primary_gen",
        "//src/mongo/db/global_catalog/ddl:placement_history_commands_gen",
        "//src/mongo/db/global_catalog/ddl:remove_shard_from_zone_request_type.cpp",
        "//src/mongo/db/global_catalog/ddl:repair_sharded_collection_chunks_history_gen",
        "//src/mongo/db/global_catalog/ddl:set_allow_migrations_gen",
        "//src/mongo/db/global_catalog/ddl:sharded_ddl_commands_gen",
        "//src/mongo/db/global_catalog/ddl:shardsvr_join_ddl_coordinators_request_gen",
        "//src/mongo/db/global_catalog/ddl:shardsvr_join_migrations_request_gen",
        "//src/mongo/db/global_catalog/ddl:untrack_unsplittable_collection_gen",
        "//src/mongo/db/global_catalog/metadata_consistency_validation:check_metadata_consistency_gen",
        "//src/mongo/db/router_role/routing_cache:shard_cannot_refresh_due_to_locks_held_exception.cpp",
        "//src/mongo/db/shard_role/ddl:clone_catalog_data_gen",
        "//src/mongo/db/shard_role/shard_catalog:flush_database_cache_updates_gen",
        "//src/mongo/db/shard_role/shard_catalog:flush_routing_table_cache_updates_gen",
        "//src/mongo/db/sharding_environment:mongod_and_mongos_server_parameters_gen",
        "//src/mongo/db/sharding_environment:sharding_feature_flags.cpp",
        "//src/mongo/db/sharding_environment:sharding_feature_flags_gen",
        "//src/mongo/db/topology:remove_shard_gen",
        "//src/mongo/db/topology/cluster_parameters:sharding_cluster_parameters_gen",
        "//src/mongo/db/versioning_protocol:get_database_version_gen",
        "//src/mongo/db/versioning_protocol:shard_version_factory.cpp",
        "//src/mongo/db/versioning_protocol:stale_exception.cpp",
        "//src/mongo/s/migration_blocking_operation:migration_blocking_operation_feature_flags_gen",
        "//src/mongo/s/request_types:abort_reshard_collection_gen",
        "//src/mongo/s/request_types:auto_split_vector_gen",
        "//src/mongo/s/request_types:balancer_collection_status_gen",
        "//src/mongo/s/request_types:cleanup_orphaned_gen",
        "//src/mongo/s/request_types:cleanup_reshard_collection_gen",
        "//src/mongo/s/request_types:cluster_commands_without_shard_key_gen",
        "//src/mongo/s/request_types:commit_reshard_collection_gen",
        "//src/mongo/s/request_types:configure_collection_balancing_gen",
        "//src/mongo/s/request_types:coordinate_multi_update_gen",
        "//src/mongo/s/request_types:flush_resharding_state_change_gen",
        "//src/mongo/s/request_types:get_stats_for_balancing_gen",
        "//src/mongo/s/request_types:migration_secondary_throttle_options.cpp",
        "//src/mongo/s/request_types:move_range_request_gen",
        "//src/mongo/s/request_types:reshard_collection_gen",
        "//src/mongo/s/request_types:resharding_operation_time_gen",
        "//src/mongo/s/request_types:transition_from_dedicated_config_server_gen",
        "//src/mongo/s/request_types:transition_to_dedicated_config_server_gen",
        "//src/mongo/s/request_types:update_zone_key_range_gen",
        "//src/mongo/s/request_types:update_zone_key_range_serialization.cpp",
        "//src/mongo/s/request_types:wait_for_fail_point_gen",
        "//src/mongo/s/resharding:common_types_gen",
        "//src/mongo/s/resharding:resharding_coordinator_service_conflicting_op_in_progress_info.cpp",
        "//src/mongo/s/resharding:resharding_feature_flag_gen",
        "//src/mongo/s/resharding:resume_token_gen",
        "//src/mongo/s/resharding:type_collection_fields_gen",
    ],
    deps = [
        ":add_shard_idl",
        ":analyze_shard_key_common",
        ":sharding_helpers",
        "//src/mongo/client:connection_string",
        "//src/mongo/client:read_preference",
        "//src/mongo/db:common",
        "//src/mongo/db:mongohasher",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db/auth:authprivilege",
        "//src/mongo/db/commands:create_command",
        "//src/mongo/db/global_catalog/metadata_consistency_validation:metadata_consistency_types_idl",
        "//src/mongo/db/matcher:path",
        "//src/mongo/db/query/query_shape",
        "//src/mongo/db/shard_role/ddl:coll_mod_command_idl",
        "//src/mongo/db/shard_role/ddl:index_commands_idl",
        "//src/mongo/db/shard_role/shard_catalog:collection_options",
        "//src/mongo/db/storage/key_string",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/topology:remove_shard_exception",
        "//src/mongo/db/topology/cluster_parameters:cluster_server_parameter_cmds_idl",
        "//src/mongo/db/topology/user_write_block:set_user_write_block_mode_idl",
        "//src/mongo/executor:async_rpc_error_info",
        "//src/mongo/executor:scoped_task_executor",
        "//src/mongo/rpc:command_status",
        "//src/mongo/util:caching",
    ],
)

mongo_cc_library(
    name = "mongos_topology_coordinator",
    srcs = [
        "//src/mongo/db/sharding_environment:mongos_hello_response.cpp",
        "//src/mongo/db/topology:mongos_topology_coordinator.cpp",
    ],
    deps = [
        "//src/mongo/bson/util:bson_extract",
        "//src/mongo/db:common",
        "//src/mongo/db:server_base",
        "//src/mongo/rpc:metadata",
        "//src/mongo/transport:transport_layer_common",
    ],
)

idl_generator(
    name = "mongos_options_gen",
    src = "mongos_options.idl",
)

mongo_cc_library(
    name = "sharding_task_executor",
    srcs = [
        "sharding_task_executor.cpp",
    ],
    deps = [
        ":sharding_router_api",
        "//src/mongo/db:operation_time_tracker",
        "//src/mongo/db:server_base",
        "//src/mongo/executor:thread_pool_task_executor",
        "//src/mongo/s/client:sharding_client",
    ],
)

mongo_cc_library(
    name = "sharding_write_without_shard_key_api",
    srcs = [
        "//src/mongo/s/write_ops:write_without_shard_key_util.cpp",
    ],
    deps = [
        ":sharding_router_api",
        "//src/mongo/db/query/write_ops:canonical_update_and_delete",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/timeseries/write_ops:timeseries_write_ops_utils",
        "//src/mongo/db/transaction:transaction_api",
        "//src/mongo/executor:inline_executor",
    ],
)

# This is the main library to use for consumers of sharding. It will pull the
# routing and targeting functionality.
#
# This is the only library, which should be referenced directly outside of
# mongo/s/ and mongo/db/s/
mongo_cc_library(
    name = "sharding_api",
    srcs = [
        "cluster_write.cpp",
    ],
    no_undefined_ref_DO_NOT_USE = False,
    deps = [
        ":sharding_router_api",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:not_primary_error_tracker",
        "//src/mongo/db/commands/query_cmd:bulk_write_common",
        "//src/mongo/db/pipeline",
        "//src/mongo/db/pipeline/process_interface:mongos_process_interface",
        "//src/mongo/db/query/write_ops:parsed_update",
        "//src/mongo/db/shard_role/shard_catalog:collection_uuid_mismatch_info",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/timeseries:timeseries_conversion_util",
        "//src/mongo/db/timeseries:timeseries_metadata",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/transaction:transaction_api",
        "//src/mongo/executor:inline_executor",
        "//src/mongo/s/query/planner:cluster_find",
        "//src/mongo/s/write_ops/unified_write_executor",
    ],
)

mongo_cc_library(
    name = "startup_initialization",
    srcs = [
        "client_transport_observer_mongos.cpp",
        "router_transactions_server_status.cpp",
        "service_entry_point_router_role.cpp",
        "//src/mongo/db/sharding_environment:s_sharding_server_status.cpp",
    ],
    deps = [
        ":load_balancer_support",
        ":sharding_router_api",
        "//src/mongo/db:curop_metrics",
        "//src/mongo/db:not_primary_error_tracker",
        "//src/mongo/db:profile_settings",
        "//src/mongo/db/session:session_catalog",
        "//src/mongo/db/stats:top",
        "//src/mongo/db/topology/cluster_parameters:cluster_server_parameter_server_status",
        "//src/mongo/s/commands:cluster_commands_common",
        "//src/mongo/transport:session_manager",
    ],
)

mongo_cc_library(
    name = "mongos_initializers",
    srcs = [
        "cluster_cursor_stats.cpp",
    ],
    deps = [
        # NOTE: If you need to add a static or mongo initializer to mongos startup,
        # please add that library here, as a private library dependency.
        "//src/mongo/db/admission:queues_server_status_section",
        "//src/mongo/db:audit",
        "//src/mongo/db/auth:authserver",
        "//src/mongo/db/commands/server_status:server_status_core",
        "//src/mongo/db/commands/server_status:server_status_servers",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:default_max_time_ms_cluster_parameter",
        "//src/mongo/db:incremental_rollout_metrics",
        "//src/mongo/db/topology/vector_clock:logical_time_metadata_hook",
        "//src/mongo/db/pipeline/process_interface:mongos_process_interface_factory",
        "//src/mongo/db/process_health:config_server_health_observer",
        "//src/mongo/db/process_health:fault_manager",
        "//src/mongo/db/query:plan_executor",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db/topology:remove_shard_exception",
        "//src/mongo/db:server_options",
        "//src/mongo/db:server_options_base",
        "//src/mongo/db/shard_role:service_context_non_d",
        "//src/mongo/db/session:session_catalog",
        "//src/mongo/db:startup_warnings_common",
        "//src/mongo/db/stats:counters",
        "//src/mongo/db/stats:latency_server_stats",
        "//src/mongo/db:vector_clock",
        "//src/mongo/executor:async_rpc_error_info",
        "//src/mongo/db/topology/cluster_parameters:cluster_server_parameter_server_status",
        "//src/mongo/otel",
        "//src/mongo/otel/traces:tracing",
        "//src/mongo/logv2/log_metric_initializer",
        "//src/mongo/transport:message_compressor_options_server",
        "//src/mongo/transport:session_manager",
        "//src/mongo/transport:transport_layer_manager",
        "//src/mongo/util:assert_util_params",
        "//src/mongo/util:clock_sources",
        "//src/mongo/util/net:http_client_impl",
        "//src/mongo/util:ntservice",
        "//src/mongo/util:observable_mutex_server_status_section",
        "//src/mongo/util/options_parser",
        "//src/mongo/util/options_parser:options_parser_init",
        "//src/mongo/util:pin_code_segments",
        "//src/mongo/util:testing_options",
        "//src/mongo/util:version_impl",
        "//src/mongo/s/commands:cluster_commands",
        "//src/mongo/s/commands:cluster_commands_common",
        "//src/mongo/s/commands:sharded_cluster_commands",
        "//src/mongo/s/commands:sharded_cluster_sharding_commands",
        "//src/mongo/db/sharding_environment:mongos_server_parameters",
        "mongos_topology_coordinator",
        "//src/mongo/s/query/exec:cluster_cursor_cleanup_job",
        "//src/mongo/db/sharding_environment:sharding_initialization",
        "sharding_router_api",
    ] + select({
        "@platforms//os:windows": ["//src/mongo/db:windows_options"],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:build_grpc_enabled": ["//src/mongo/transport/grpc:grpc_transport_server_options"],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:ssl_enabled": ["//src/mongo/util/net:ssl_options_server"],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:tcmalloc_google_enabled": ["//src/mongo/util:tcmalloc_set_parameter"],
        "//bazel/config:tcmalloc_gperf_enabled": ["//src/mongo/util:tcmalloc_set_parameter"],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:use_tracing_profiler_enabled": ["//src/mongo/util/tracing_profiler"],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:enterprise_feature_audit_enabled": [
            "//src/mongo/db/modules/enterprise/src/audit:audit_configuration",
            "//src/mongo/db/modules/enterprise/src/audit:audit_mongos",
        ],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:enterprise_feature_encryptdb_enabled": [
            "//src/mongo/db/modules/enterprise/src/encryptdb:log_redact_options",
        ],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:enterprise_feature_fips_enabled": [
            "//src/mongo/db/modules/enterprise/src/fips:fips_mode_server",
        ],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:enterprise_feature_ldap_enabled": [
            "//src/mongo/db/modules/enterprise/src/ldap:ldap_health_observer",
            "//src/mongo/db/modules/enterprise/src/ldap:ldap_manager_init",
        ],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:enterprise_feature_sasl_enabled": [
            "//src/mongo/db/modules/enterprise/src/sasl:auth_delay",
            "//src/mongo/db/modules/enterprise/src/sasl:authz_manager_factory_enterprise",
            "//src/mongo/db/modules/enterprise/src/sasl:mongosaslservercommon",
        ],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:enterprise_feature_audit_or_encryptdb_enabled": [
            "//src/mongo/db/modules/enterprise/src/kmip:kmip_configuration",
        ],
        "//conditions:default": [],
    }),
)

mongo_cc_library(
    name = "mongos_main",
    srcs = [
        "mongos_main.cpp",
        "mongos_options.cpp",
        "mongos_options_gen",
        "mongos_options_init.cpp",
        "read_write_concern_defaults_cache_lookup_mongos.cpp",
        "//src/mongo/db/sharding_environment:version_mongos.cpp",
    ],
    deps = [
        # NOTE: Do not add new libdeps (public or private) here unless
        # required by the linker to satisfy symbol dependencies from
        # the files listed above in `sources`. If you need to add a
        # library to inject a static or mongo initializer to mongos,
        # please add that library as a private libdep of
        # mongos_initializers.
        "//src/mongo/client:remote_command_targeter",
        "//src/mongo/db:audit",
        "//src/mongo/db/auth:authserver",
        "//src/mongo/db:change_stream_options_manager",
        "//src/mongo/db/commands:profile_common",
        "//src/mongo/db/commands:rwc_defaults_commands",
        "//src/mongo/db/exec:scoped_timer",
        "//src/mongo/db/extension/host:extension_loader",
        "//src/mongo/db/ftdc:ftdc_mongos",
        "//src/mongo/db/process_health:fault_manager",
        "//src/mongo/db/query/query_settings:query_settings_service",
        "//src/mongo/db/query/search:search_task_executors",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db:serverinit",
        "//src/mongo/db/session:kill_sessions_remote",
        "//src/mongo/db/session:logical_session_cache_impl",
        "//src/mongo/db/session:session_catalog",
        "//src/mongo/db:startup_warnings_common",
        "//src/mongo/db/topology/cluster_parameters:cluster_server_parameter_refresher",
        "//src/mongo/otel/traces:tracing_initialization",
        "//src/mongo/transport:ingress_handshake_metrics",
        "//src/mongo/transport:service_executor",
        "//src/mongo/transport:session_manager",
        "//src/mongo/transport:transport_layer_manager",
        "//src/mongo/util:allocator_thread",
        "//src/mongo/util:periodic_runner_factory",
        "//src/mongo/util:signal_handlers",
        "//src/mongo/s/client:sharding_client",
        "//src/mongo/s/change_streams",
        "//src/mongo/s/commands:cluster_commands",
        "//src/mongo/s/commands:cluster_commands_common",
        "load_balancer_support",
        "mongos_initializers",
        "mongos_topology_coordinator",
        "//src/mongo/s/query/exec:cluster_cursor_cleanup_job",
        "//src/mongo/db/shard_role:resource_yielders",
        "//src/mongo/db/global_catalog/ddl:sessions_collection_sharded",
        "//src/mongo/db/sharding_environment:sharding_initialization",
        "sharding_router_api",
        "startup_initialization",
    ] + select({
        "//bazel/config:use_tracing_profiler_enabled": [
            "//src/mongo/util/tracing_profiler",
        ],
        "//conditions:default": [],
    }) + select({
        "//bazel/config:enterprise_feature_audit_enabled": [
            "//src/mongo/db/modules/enterprise/src/audit:audit_enterprise",
        ],
        "//conditions:default": [],
    }),
)

windows_rc(
    name = "mongos_res",
    src = "mongos.rc",
    icon = "//src/mongo/db:mongo.ico",
    manifest_in = "mongos.manifest.in",
)

mongo_cc_binary(
    name = "mongos",
    srcs = [
        "mongos.cpp",
    ],
    linkopts = select({
        "@platforms//os:linux": [
            "-ldl",
            "-lrt",
        ],
        "//conditions:default": [],
    }),
    tags = [
        "devcore",
        "dist_test",
    ],
    deps = [
        # NOTE: Do not add new deps here unless required by the linker to
        # satisfy symbol dependencies from the files listed above in `sources`. If you need to add a
        # library to inject a static or mongo initializer to mongos, please add that library as a
        # dep of mongos_initializers.
        "mongos_main",
        "//src/mongo/db:server_base",
        "mongos_res",
    ],
)

mongo_cc_unit_test(
    name = "s_test",
    srcs = [
        "append_raw_responses_test.cpp",
        "async_requests_sender_test.cpp",
        "async_rpc_shard_targeter_test.cpp",
        "balancer_configuration_test.cpp",
        "load_balancer_support_test.cpp",
        "query_analysis_sample_tracker_test.cpp",
        "query_analysis_sampler_test.cpp",
        "sharding_task_executor_test.cpp",
        "transaction_router_test.cpp",
        "//src/mongo/db/global_catalog:chunk_manager_query_test.cpp",
        "//src/mongo/db/global_catalog:chunk_manager_test.cpp",
        "//src/mongo/db/global_catalog:chunk_map_test.cpp",
        "//src/mongo/db/global_catalog:chunk_test.cpp",
        "//src/mongo/db/global_catalog:chunks_test_util.cpp",
        "//src/mongo/db/global_catalog:shard_key_pattern_query_util_chunk_ranges_test.cpp",
        "//src/mongo/db/global_catalog:shard_key_pattern_query_util_index_bounds_test.cpp",
        "//src/mongo/db/global_catalog:shard_key_pattern_test.cpp",
        "//src/mongo/db/global_catalog:sharding_catalog_client_read_preference_test.cpp",
        "//src/mongo/db/global_catalog:sharding_catalog_client_test.cpp",
        "//src/mongo/db/global_catalog:sharding_catalog_write_retry_test.cpp",
        "//src/mongo/db/global_catalog:type_changelog_test.cpp",
        "//src/mongo/db/global_catalog:type_chunk_range_test.cpp",
        "//src/mongo/db/global_catalog:type_chunk_test.cpp",
        "//src/mongo/db/global_catalog:type_collection_test.cpp",
        "//src/mongo/db/global_catalog:type_config_version_test.cpp",
        "//src/mongo/db/global_catalog:type_database_test.cpp",
        "//src/mongo/db/global_catalog:type_mongos_test.cpp",
        "//src/mongo/db/global_catalog:type_shard_test.cpp",
        "//src/mongo/db/global_catalog:type_tags_test.cpp",
        "//src/mongo/db/global_catalog/ddl:add_shard_to_zone_request_test.cpp",
        "//src/mongo/db/global_catalog/ddl:merge_chunks_request_test.cpp",
        "//src/mongo/db/global_catalog/ddl:remove_shard_from_zone_request_test.cpp",
        "//src/mongo/db/global_catalog/ddl:sessions_collection_sharded_test.cpp",
        "//src/mongo/db/router_role:collection_routing_info_targeter_test.cpp",
        "//src/mongo/db/router_role:mock_ns_targeter.cpp",
        "//src/mongo/db/router_role:router_role_test.cpp",
        "//src/mongo/db/router_role:routing_table_cache_gossip_metadata_hook_test.cpp",
        "//src/mongo/db/router_role:routing_table_history_test.cpp",
        "//src/mongo/db/router_role/routing_cache:catalog_cache_refresh_test.cpp",
        "//src/mongo/db/router_role/routing_cache:catalog_cache_test.cpp",
        "//src/mongo/db/sharding_environment:cluster_identity_loader_test.cpp",
        "//src/mongo/db/sharding_environment/client:config_shard_wrapper_test.cpp",
        "//src/mongo/db/sharding_environment/client:shard_remote_test.cpp",
        "//src/mongo/db/topology:mongos_topology_coordinator_test.cpp",
        "//src/mongo/db/topology:shard_registry_test.cpp",
        "//src/mongo/db/versioning_protocol:chunk_version_test.cpp",
        "//src/mongo/db/versioning_protocol:comparable_chunk_version_test.cpp",
        "//src/mongo/db/versioning_protocol:comparable_database_version_test.cpp",
        "//src/mongo/db/versioning_protocol:shard_version_test.cpp",
        "//src/mongo/db/versioning_protocol:stale_exception_test.cpp",
        "//src/mongo/s/request_types:migration_secondary_throttle_options_test.cpp",
        "//src/mongo/s/request_types:update_zone_key_range_request_test.cpp",
        "//src/mongo/s/write_ops:batch_write_exec_test.cpp",
        "//src/mongo/s/write_ops:batch_write_op_test.cpp",
        "//src/mongo/s/write_ops:batched_command_request_test.cpp",
        "//src/mongo/s/write_ops:batched_command_response_test.cpp",
        "//src/mongo/s/write_ops:bulk_write_command_modifier_test.cpp",
        "//src/mongo/s/write_ops:bulk_write_exec_test.cpp",
        "//src/mongo/s/write_ops:write_op_test.cpp",
        "//src/mongo/s/write_ops:write_without_shard_key_util_test.cpp",
    ],
    tags = [
        "mongo_unittest_sixth_group",
    ],
    deps = [
        ":load_balancer_support",
        ":mongos_topology_coordinator",
        ":sharding_api",
        ":sharding_task_executor",
        "//src/mongo/db:mongohasher",
        "//src/mongo/db:vector_clock",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/global_catalog:sharding_catalog_client_mock",
        "//src/mongo/db/global_catalog/ddl:sessions_collection_sharded",
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/db/pipeline/process_interface:mongos_process_interface_factory",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/query/write_ops:parsed_update",
        "//src/mongo/db/query/write_ops:write_ops_parsers_test_helpers",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/shard_role:service_context_non_d",
        "//src/mongo/db/sharding_environment:sharding_initialization",
        "//src/mongo/db/sharding_environment:sharding_mongos_test_fixture",
        "//src/mongo/db/sharding_environment:unittest_noop_sharding_initialization_mongod",
        "//src/mongo/db/timeseries:timeseries_conversion_util",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/topology/cluster_parameters:cluster_server_parameter",
        "//src/mongo/executor:async_rpc",
        "//src/mongo/s/commands:cluster_commands",
        "//src/mongo/s/commands:cluster_commands_common",
        "//src/mongo/util:periodic_runner_factory",
        "//src/mongo/util/net:network",
    ],
)

mongo_cc_unit_test(
    name = "service_entry_point_router_role_test",
    srcs = [
        "service_entry_point_router_role_test.cpp",
    ],
    tags = ["mongo_unittest_fourth_group"],
    deps = [
        ":startup_initialization",
        "//src/mongo/db/auth:authserver",
        "//src/mongo/db/shard_role:service_context_non_d",
        "//src/mongo/db/sharding_environment:unittest_noop_sharding_initialization_mongod",
        "//src/mongo/rpc:message",
        "//src/mongo/transport:service_entry_point_test_fixture",
        "//src/mongo/util:version_impl",
    ],
)

mongo_cc_benchmark(
    name = "service_entry_point_router_role_bm",
    srcs = ["service_entry_point_router_role_bm.cpp"],
    tags = ["sep_bm"],
    deps = [
        ":startup_initialization",
        "//src/mongo/db:read_write_concern_defaults_mock",
        "//src/mongo/db/auth:authserver",
        "//src/mongo/db/shard_role:service_context_non_d",
        "//src/mongo/rpc:message",
        "//src/mongo/unittest:benchmark_util",
    ],
)

mongo_cc_unit_test(
    name = "multi_statement_transaction_requests_sender_test",
    srcs = [
        "multi_statement_transaction_requests_sender_test.cpp",
    ],
    tags = ["mongo_unittest_third_group"],
    deps = [
        ":sharding_api",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/sharding_environment:shard_server_test_fixture",
        "//src/mongo/db/sharding_environment:sharding_mongos_test_fixture",
        "//src/mongo/s/commands:cluster_commands",
    ],
)
